package pl.edu.agh.intobl.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public abstract class SolomonConverter {

	private static final String filename = "c202";
	private static final String PATH = "./src/main/resources/test-cases/" + filename + ".txt";
	
	public static void main(String[] args) throws IOException {
		File inputFile = new File(PATH);
		File outputFile = new File(inputFile.getParent(), inputFile.getName().substring(0, inputFile.getName().length()-4) + "_converted.txt");
		BufferedReader reader = new BufferedReader(new FileReader(inputFile));
		BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
		
		List<String> readLines = new ArrayList<String>();
		readLines.add("200\n");
		String line;
		while ((line = reader.readLine()) != null) {
			String[] arrayedLine = line.split("\\s+");
			for (int i=0; i<arrayedLine.length; i++)
				if (arrayedLine[i].length() > 0)
					readLines.add(Double.valueOf(arrayedLine[i]).intValue() + " ");
			
			readLines.add("\n");
		}
		
		for (int i=0; i<readLines.size(); i++) {
			writer.write(readLines.get(i));
		}
		
		reader.close();
		writer.close();
	}
}
